package jlaw.client;


import com.explodingpixels.widgets.PopupMenuCustomizerUsingStrings;
import com.explodingpixels.widgets.WindowUtils;
import com.explodingpixels.macwidgets.*;


import javax.swing.JOptionPane;
import javax.swing.JTextField;
//import javax.ejb.EJB;
import javax.naming.NamingException;
import javax.naming.InitialContext;

import jlaw.ejb.interfaces.*;
import jlaw.entitats.*;
import javax.swing.JFrame;
import jlaw.client.*;


public class PantallaLoginControlador  {
// @EJB
  //  private static MetodeUsuari mu;


	private JTextField login;
	private JTextField password;
	
	
	
	public void valida(){
				System.out.println("classe controladora"); // Announce "sucursal found"

	MetodeUsuari mu = null;
	try {
			InitialContext ctx = new InitialContext(); // Create context for EJB lookup
			mu = (MetodeUsuari)ctx.lookup("jlaw.ejb.interfaces.MetodeUsuari"); // Locate EJB “ejb/PersonalService”
		} catch (NamingException ex) { // We have to count with possible errors here
			System.out.println("Failed to get the reference to PersonalService. Details: " + ex.toString());
			System.exit(1); // Stop the exercizer here due to a fatal error
		}
		System.out.println("sds");
				
        Usuari user3 = null;
       
        user3=new Usuari();
        user3.setLogin(login.getText());
        user3.setPassword(password.getText());
        System.out.println(user3.getLogin()+user3.getPassword());
            	System.out.println("afegeire l usuari anter2ior");
            			System.out.println(mu.saluda());

	     //  mu.afegirUsuari(user3);
	       //            	System.out.println("sha afegit correctament ara l buscare");

	     System.out.println(mu.existeixUsuari(user3));
	     //              	System.out.println("no va?");


if (mu.existeixUsuari(user3)){
			JOptionPane.showMessageDialog(null, "succes");
			//Main.fp();
	//JFrame frame2 = PantallaPrincipal.crea(new PantallaPrincipalControlador("Jlaw: Main"));
	//frame2.pack();
	//frame2.setLocationRelativeTo(null);

	//frame2.setVisible(true);
	System.out.println("1");

	JFrame frame2 = new JFrame();
	System.out.println("2");

	MacUtils.makeWindowLeopardStyle(frame2.getRootPane());
	System.out.println("3");

	WindowUtils.createAndInstallRepaintWindowFocusListener(frame2);
	System.out.println("ara creem una PP");
	PantallaPrincipal everything = new PantallaPrincipal(frame2);
	System.out.println("pp creada");
	frame2.setSize(650, 450);
	frame2.setLocationRelativeTo(null);
	frame2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	frame2.setVisible(true);
	
		} else{
			JOptionPane.showMessageDialog(null, "fail");

		}

System.out.println("surto o no");

	}
	
	public JTextField getLogin() {
		return login;
	}

	public void setLogin(JTextField login) {
		this.login = login;
	}

	public JTextField getPassword() {
		return password;
	}

	public void setPassword(JTextField password) {
		this.password = password;
	}

	public void cancela(){
		
		        System.exit(0);
	}
}
